package com.lu.rpc.proxy.core.config;

import com.lu.rpc.proxy.core.clients.domain.response.RpcResponse;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;

/**
 * rpc应用上下文
 *
 * @author: zhanglu
 * @date: 2023/7/7 12:16
 * @modify: 修改人信息, 修改内容 2023/7/7 12:16
 */
public class RpcApplicationContext implements ApplicationContextAware{

    public static final ThreadLocal<RpcResponse> RPC_RESPONSE_THREAD_LOCAL = new InheritableThreadLocal<>();

    private static ApplicationContext APPLICATION_CONTEXT;

    private static ResourceLoader RESOURCE_LOADER;

    private static Environment ENVIRONMENT;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        APPLICATION_CONTEXT = applicationContext;
    }

    public static void setEnvironment(Environment environment) {
        ENVIRONMENT = environment;
    }

    public static void setResourceLoader(ResourceLoader resourceLoader) {
        RESOURCE_LOADER = resourceLoader;
    }

    public static ApplicationContext getApplicationContext() {
        return APPLICATION_CONTEXT;
    }

    public static ResourceLoader getResourceLoader() {
        return RESOURCE_LOADER;
    }

    public static Environment getEnvironment() {
        return ENVIRONMENT;
    }
}
